package com.yunhe.java.Day13;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

/**
 * Created by Administrator on 2017/8/7 0007.
 */
public class TreeSetPaiXu {
    public static void main(String[] args) {
        Set<Java> set= new TreeSet<>(new Comparator<Java>() {
            @Override
            public int compare(Java o1, Java o2) {
                int n=0;
                if(o1.getId().hashCode()>o2.getId().hashCode()){
                    n=1;

                }else if(o1.getId().hashCode()<o2.getId().hashCode()){
                   n=-1;
                }
                return n;
            }
        });

        set.add(new Java("王一",19,"Java-05"));
        set.add(new Java("王二",25,"Java-01"));
        set.add(new Java("王三",20,"Java-03"));
        set.add( new Java("王四",23,"Java-07"));
        for (Java ja:set){
            System.out.println(ja.getId()+" "+ja.getName()+" "+ja.getAge());
        }

    }
}
